package com.kun.base.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author likun
 * 2018/5/2 14:34
 **/
@Component
@Configuration
@EnableSwagger2
@EnableWebMvc
@ComponentScan("com.**.controller")
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
//        Predicate<RequestHandler> predicate = input -> {
//            Class<?> declaringClass = input.declaringClass();
//            if (declaringClass == BasicErrorController.class)// 排除
//                return false;
//            if(declaringClass.isAnnotationPresent(RestController.class)) // 被注解的类
//                return true;
//            if(input.isAnnotatedWith(ResponseBody.class)) // 被注解的方法
//                return true;
//            return false;
//        };
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false)
                .select()
//                .apis(predicate)
                .apis(RequestHandlerSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("ssm整合API接口")
                .description("框架api说明")
                .termsOfServiceUrl("https://gitee.com/likunlikunlikun")
                .contact(new Contact("likun","https://gitee.com/likunlikunlikun","likunlikunlikun@outlook.com"))
                .version("1.0")
                .build();
    }
}
